package com.chinatsp.onlineapp.ui.weather;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.chinatsp.onlineapp.R;
import com.chinatsp.onlineapp.bean.WeatherService.RespDataBean;

public class WeatherCitysAdapter extends BaseAdapter{
	
	private RespDataBean data;
	private Context mContext;
	
	public WeatherCitysAdapter(Context context){
		mContext = context;	
	}
	
	
	public WeatherCitysAdapter(Context context,RespDataBean bean){
		mContext = context;
		data = bean;
	}
	
	
	@Override
	public int getCount() {		
//		return data.getForecast_conditions()==null?0:data.getForecast_conditions().size();
		return 3;
	}

	@Override
	public Object getItem(int arg0) {
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		return 0;
	}

	class Holder{
		TextView  tv_date;
		TextView tv_week;
		ImageView iv_weather;
		TextView tv_temperature;
		TextView tv_weather;
	}
	
	
	@Override
	public View getView(int position, View  convertView, ViewGroup viewgroup) {
		Holder holder;
		if (convertView == null) {
			holder = new Holder();
			convertView = LayoutInflater.from(mContext).inflate(R.layout.item_list_body, null,false);
			holder.tv_date = (TextView) convertView.findViewById(R.id.tv_data);
			holder.tv_week = (TextView) convertView.findViewById(R.id.tv_week);
			holder.iv_weather = (ImageView) convertView.findViewById(R.id.iv_weather);
			holder.tv_temperature= (TextView) convertView.findViewById(R.id.tv_temp);
			holder.tv_weather = (TextView) convertView.findViewById(R.id.tv_wea);
			convertView.setTag(holder);
		}else{
			holder = (Holder) convertView.getTag();
		}		
		String date = data.getForecast_conditions().get(position).getWeather_date();
		String week = data.getForecast_conditions().get(position).getWeather_week();
		String iv = data.getForecast_conditions().get(position).getWeather_condition();
		String temperation = data.getForecast_conditions().get(position).getLow_temperature()
				+"/"+ data.getForecast_conditions().get(position).getHigh_temperature();
		String weather = data.getForecast_conditions().get(position).getWeather_condition();
		
		holder.tv_date.setText(date);
		holder.tv_week.setText(week);
//		holder.iv_weather.setImageResource(resId)
		holder.tv_temperature.setText(temperation);
		holder.tv_weather.setText(weather);		
		return convertView;
	}

}
